/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t0 =Thread.currentThread();
        Thread t1 = new Thread(()->{
            for(int i=0;i<3;i++){

                try {
                    Thread.sleep(0);
                    Thread.sleep(2000);

                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{
            try {
                t0.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        System.out.println(t1.getState()); //此时还为开始任务，所以为 new
        t2.start();
        t1.start();
        System.out.println(t1.getState()); //此时刚开始任务，没执行到sleep(0),为工作中状态，执行到为就绪状态，所以为 RUNNABLE
        Thread.sleep(1000);
        System.out.println(t1.getState()); //刚好碰到 t1睡眠 2 秒，为等待状态，但只等有限时间，所以为 TIMED_WAITING
        System.out.println(t2.getState()); //此时 t2 在等 main 线程结束。等的是未知时间。所以为 WAITING
        t1.join();
        System.out.println(t1.getState()); //此时等到了 t1 执行完了，工作结束，所以为 TERMINATED
    }
}
